Skip to content

fix: keep data textures linear when set through the scene-graph API - #5230

Open
HEOJUNFO wants to merge 1 commit into
google:masterfrom
HEOJUNFO:fix-extension-texture-color-space
Open

HEOJUNFO wants to merge 1 commit into
google:masterfrom
HEOJUNFO:fix-extension-texture-color-space

Conversation

@HEOJUNFO

@HEOJUNFO HEOJUNFO commented Dec 1, 2026

Copy link
Copy Markdown

Reference Issue

None. Found while reading TextureInfo.setTexture().

Description

A texture set on a non-color extension slot through the scene-graph API is sampled as sRGB, so the material renders differently from the same image referenced by the glTF.

const material = modelViewer.model.materials[0];
const texture = await modelViewer.createTexture('normals.png');
material.clearcoatNormalTexture.setTexture(texture);
// The three.js texture now has colorSpace 'srgb'; a normal map is linear data.

createTexture() returns an sRGB texture (scene-graph.ts L134). TextureInfo.setTexture() starts from sRGB (texture-info.ts L137) and switches to linear only for the metallic-roughness, normal and occlusion slots. These ten slots keep sRGB: clearcoatTexture, clearcoatRoughnessTexture, clearcoatNormalTexture, sheenRoughnessTexture, transmissionTexture, thicknessTexture, specularTexture, iridescenceTexture, iridescenceThicknessTexture, anisotropyTexture.

To measure it I loaded ClearCoatTest.gltf from glTF-Sample-Assets and set the model's own images again on the slots they already use (PartialCoating.png on clearcoatTexture, RoughnessStripes.png on clearcoatRoughnessTexture, PlasticWrap_normals.jpg and RibsNormal.png on clearcoatNormalTexture). The frame should stay the same.

800x600 frame, as loaded vs. after setTexture() max channel difference pixels differing by more than 8/255
master 227 6909
this PR 0 0

Fix

Set those ten slots to LinearSRGBColorSpace, the way the three existing data slots do. This matches GLTFLoader, which passes SRGBColorSpace only for base color, emissive, sheen color and specular color. Those four stay sRGB.

sheenRoughnessTexture and specularTexture are read from the alpha channel, so for them only the tag changes.

Tests

Added setTexture sets the color space the slot expects to texture-info-spec.ts. On master it fails with clearcoatTexture: expected 'srgb' to equal 'srgb-linear'.

specularColorTexture is not in the test. Its getter returns the sheen color slot (material.ts L567), which is a separate fix.

Ran on Chromium (headless, SwiftShader) with the options of web-test-ci.config.mjs:

web-test-runner --files lib/test/features/scene-graph/texture-info-spec.js lib/test/features/scene-graph/material-spec.js lib/test/features/scene-graph/texture-spec.js
3/3 test files | 28 passed, 0 failed

eslint on the two changed files reports no errors. I did not run WebKit or Firefox.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

TextureInfo.setTexture() tagged every texture as sRGB except the
metallic-roughness, normal and occlusion maps. The clearcoat, clearcoat
roughness, clearcoat normal, sheen roughness, transmission, thickness,
specular, iridescence, iridescence thickness and anisotropy slots hold
non-color data, so a texture set on one of them was decoded as sRGB and
rendered differently from the same image loaded with the model.

Set those slots to linear, as GLTFLoader does. Base color, emissive,
sheen color and specular color stay sRGB.
@HEOJUNFO
HEOJUNFO force-pushed the fix-extension-texture-color-space branch from a6a9718 to 220221e Compare December 1, 2026 10:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant